\hypertarget{tcpserver_8c}{
\section{/home/tech/release/K210-Devkit-CDROM-v1\_\-0\_\-3/subversion/nanostack/Tools/n\-Route/tcpserver.c File Reference}
\label{tcpserver_8c}\index{/home/tech/release/K210-Devkit-CDROM-v1_0_3/subversion/nanostack/Tools/nRoute/tcpserver.c@{/home/tech/release/K210-Devkit-CDROM-v1\_\-0\_\-3/subversion/nanostack/Tools/nRoute/tcpserver.c}}
}
{\tt \#include $<$sys/types.h$>$}\par
{\tt \#include $<$sys/socket.h$>$}\par
{\tt \#include $<$netinet/in.h$>$}\par
{\tt \#include $<$arpa/inet.h$>$}\par
{\tt \#include $<$sys/poll.h$>$}\par
{\tt \#include $<$sys/stat.h$>$}\par
{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$fcntl.h$>$}\par
{\tt \#include $<$errno.h$>$}\par
{\tt \#include $<$unistd.h$>$}\par
{\tt \#include $<$syslog.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$stdarg.h$>$}\par
{\tt \#include $<$sys/time.h$>$}\par
{\tt \#include $<$time.h$>$}\par
{\tt \#include $<$pthread.h$>$}\par
{\tt \#include $<$sys/ipc.h$>$}\par
{\tt \#include $<$sys/msg.h$>$}\par
{\tt \#include \char`\"{}n\-Routed.h\char`\"{}}\par
{\tt \#include \char`\"{}port.h\char`\"{}}\par
{\tt \#include \char`\"{}tcpserver.h\char`\"{}}\par
{\tt \#include \char`\"{}nrp.h\char`\"{}}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
void $\ast$ \hyperlink{tcpserver_8c_0eb8fdec50bfdfa77f5dca2e40ba7f99}{process\_\-tcp\_\-connection} (void $\ast$fd)
\item 
int \hyperlink{tcpserver_8c_670df12c784cbf1b260ab50397194b66}{tcp\_\-server} (void)
\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
\hyperlink{structnRdconfig__t}{n\-Rdconfig\_\-t} \hyperlink{tcpserver_8c_f140eca56a91b1d202fdae8f6585f42a}{n\-Rdconf}
\item 
unsigned char \hyperlink{tcpserver_8c_7e822c1df17d0b694e2b16378a39ef47}{nrp\_\-proto\_\-table} \mbox{[}32\mbox{]}\mbox{[}64\mbox{]}
\item 
unsigned char \hyperlink{tcpserver_8c_307304cf297a55eb10df201dc55abd15}{nrp\_\-addr\_\-table} \mbox{[}32\mbox{]}\mbox{[}128\mbox{]}
\item 
int \hyperlink{tcpserver_8c_47edf10920788f9aa97540340c5ff606}{haltsystem}
\item 
char \hyperlink{tcpserver_8c_7564d12ad7b7d93d5ba603fc704d855a}{n\-Routed\_\-lockfile} \mbox{[}64\mbox{]}
\end{CompactItemize}


\subsection{Detailed Description}
TCP server functionality.

All the TCP server functionality is implmented in this file. 

\subsection{Function Documentation}
\hypertarget{tcpserver_8c_0eb8fdec50bfdfa77f5dca2e40ba7f99}{
\index{tcpserver.c@{tcpserver.c}!process_tcp_connection@{process\_\-tcp\_\-connection}}
\index{process_tcp_connection@{process\_\-tcp\_\-connection}!tcpserver.c@{tcpserver.c}}
\subsubsection[process\_\-tcp\_\-connection]{\setlength{\rightskip}{0pt plus 5cm}void $\ast$ process\_\-tcp\_\-connection (void $\ast$ {\em fd})}}
\label{tcpserver_8c_0eb8fdec50bfdfa77f5dca2e40ba7f99}


\begin{Desc}
\item[\hyperlink{todo__todo000017}{Todo}]The connection configuration packet timeout needs to be implemented. -mjs \end{Desc}
\begin{Desc}
\item[\hyperlink{todo__todo000017}{Todo}]The conf. packet parsing below supports only RAW packets with certainty. Needs more work. -mjs \end{Desc}
\begin{Desc}
\item[\hyperlink{todo__todo000017}{Todo}]Must implement logic to decide if all the necessary information has been given to activate the connection. At the moment it is enough to receive a packet which has Type ID 3. -mjs \end{Desc}
\begin{Desc}
\item[\hyperlink{todo__todo000017}{Todo}]Destination address filter needs to be implmented into \hyperlink{tcpserver_8c_0eb8fdec50bfdfa77f5dca2e40ba7f99}{process\_\-tcp\_\-connection()}... -mjs \end{Desc}
\begin{Desc}
\item[\hyperlink{todo__todo000017}{Todo}]TCP server must use poll()!!! -mjs \end{Desc}
\hypertarget{tcpserver_8c_670df12c784cbf1b260ab50397194b66}{
\index{tcpserver.c@{tcpserver.c}!tcp_server@{tcp\_\-server}}
\index{tcp_server@{tcp\_\-server}!tcpserver.c@{tcpserver.c}}
\subsubsection[tcp\_\-server]{\setlength{\rightskip}{0pt plus 5cm}int tcp\_\-server (void)}}
\label{tcpserver_8c_670df12c784cbf1b260ab50397194b66}


The TCP server.

This function creates a simple TCP server which listens to specified port at address 127.0.0.1.

\begin{Desc}
\item[\hyperlink{todo__todo000016}{Todo}]Must make sure that the server notices when the peer hangs/drops the connection and acts properly. -mjs \end{Desc}


\subsection{Variable Documentation}
\hypertarget{tcpserver_8c_47edf10920788f9aa97540340c5ff606}{
\index{tcpserver.c@{tcpserver.c}!haltsystem@{haltsystem}}
\index{haltsystem@{haltsystem}!tcpserver.c@{tcpserver.c}}
\subsubsection[haltsystem]{\setlength{\rightskip}{0pt plus 5cm}int \hyperlink{tcpserver_8c_47edf10920788f9aa97540340c5ff606}{haltsystem}}}
\label{tcpserver_8c_47edf10920788f9aa97540340c5ff606}


System communications.

If an unrecoverable error occures in some of the daemons threads, the thread must set this system wide variable into 1. All threads must check this variable from time to time (interval $<$ 3 seconds) to see if they must stop execution and return to the main function which will then exit the whole daemon. \hypertarget{tcpserver_8c_f140eca56a91b1d202fdae8f6585f42a}{
\index{tcpserver.c@{tcpserver.c}!nRdconf@{nRdconf}}
\index{nRdconf@{nRdconf}!tcpserver.c@{tcpserver.c}}
\subsubsection[nRdconf]{\setlength{\rightskip}{0pt plus 5cm}struct \hyperlink{structnRdconfig__t}{n\-Rdconfig\_\-t} \hyperlink{tcpserver_8c_f140eca56a91b1d202fdae8f6585f42a}{n\-Rdconf}}}
\label{tcpserver_8c_f140eca56a91b1d202fdae8f6585f42a}


Configuration struct.

The global variable that contains the configuration data. The default values of some parameters are assigned to the variable in \hyperlink{nRouted_8c_f9f24c4cf29126b1832517b188aeb585}{parse\_\-config()}. \hypertarget{tcpserver_8c_7564d12ad7b7d93d5ba603fc704d855a}{
\index{tcpserver.c@{tcpserver.c}!nRouted_lockfile@{nRouted\_\-lockfile}}
\index{nRouted_lockfile@{nRouted\_\-lockfile}!tcpserver.c@{tcpserver.c}}
\subsubsection[nRouted\_\-lockfile]{\setlength{\rightskip}{0pt plus 5cm}char \hyperlink{tcpserver_8c_7564d12ad7b7d93d5ba603fc704d855a}{n\-Routed\_\-lockfile}\mbox{[}64\mbox{]}}}
\label{tcpserver_8c_7564d12ad7b7d93d5ba603fc704d855a}


The n\-Routed lock file.

When n\-Routed is started it eventually checks if a lock file exists. This is done so that only one instance of n\-Routed is running simultaneously. \hypertarget{tcpserver_8c_307304cf297a55eb10df201dc55abd15}{
\index{tcpserver.c@{tcpserver.c}!nrp_addr_table@{nrp\_\-addr\_\-table}}
\index{nrp_addr_table@{nrp\_\-addr\_\-table}!tcpserver.c@{tcpserver.c}}
\subsubsection[nrp\_\-addr\_\-table]{\setlength{\rightskip}{0pt plus 5cm}unsigned char \hyperlink{tcpserver_8c_307304cf297a55eb10df201dc55abd15}{nrp\_\-addr\_\-table}\mbox{[}32\mbox{]}\mbox{[}128\mbox{]}}}
\label{tcpserver_8c_307304cf297a55eb10df201dc55abd15}


The n\-RP address type lookup table.

This table contains the \char`\"{}mappings\char`\"{} between the n\-RP address type identifiers (one octet values) and their names. \hypertarget{tcpserver_8c_7e822c1df17d0b694e2b16378a39ef47}{
\index{tcpserver.c@{tcpserver.c}!nrp_proto_table@{nrp\_\-proto\_\-table}}
\index{nrp_proto_table@{nrp\_\-proto\_\-table}!tcpserver.c@{tcpserver.c}}
\subsubsection[nrp\_\-proto\_\-table]{\setlength{\rightskip}{0pt plus 5cm}unsigned char \hyperlink{tcpserver_8c_7e822c1df17d0b694e2b16378a39ef47}{nrp\_\-proto\_\-table}\mbox{[}32\mbox{]}\mbox{[}64\mbox{]}}}
\label{tcpserver_8c_7e822c1df17d0b694e2b16378a39ef47}


The n\-RP protocol lookup table.

This table is used to have a relation between the n\-RP internal protocol numbering and their humanreadable string representations. The maximum amount of different protocols is at the moment 32 and the maximum length of each string representation is 63 characters. 